package com.restaurant.application.root.support;

import com.google.common.collect.Lists;
import com.nebutown.generation.Convert;
import com.nebutown.generation.PickableBean;

import java.util.List;

public class RootPageData implements PickableBean {

    public static final String FN_ID = "id";

    public static final List<String> FIELD_NAMES = Lists.newArrayList(
            FN_ID);

    private String id;

    public RootPageData(String id) {
        setId(id);
    }

    public RootPageData() {
    }

    public RootPageData duplicate() {
        RootPageData result = new RootPageData();
        result.id = this.id;
        return result;
    }

    @Override
    public String toString() {
        return Convert.toJson(this);
    }

    public String getId() {
        return id;
    }

    public void setId(String value) {
        this.id = value;
    }

    public RootPageData withId(String value) {
        setId(value);
        return this;
    }

    public RootPageData withId(String value, String defaultValue) {
        setId(value == null ? defaultValue : value);
        return this;
    }

    public Object getValueOf(String name) {
        switch (name) {
            case "id":
                return getId();
        }
        return null;
    }

    public boolean hasField(String name) {
        return FIELD_NAMES.contains(name);
    }

    @Override
    public int hashCode() {
        return signature().hashCode();
    }

    @Override
    public boolean equals(Object o) {
        if (!(o instanceof RootPageData)) return false;
        return signature().equals(((RootPageData) o).signature());
    }

    public String signature() {
        throw new RuntimeException("Bean RootPageData has no signature defined, no hash code or equals possible.");
    }
}
